package BlackJack.View
{
	import BlackJack.Model.Events.LobbyEvent;
	import org.robotlegs.mvcs.Mediator;

	public class LobbyMediator extends Mediator
	{
		[Inject]
		public var view:Lobby;

		public function LobbyMediator()
		{
			super();
		}

		override public function onRegister():void
		{
			for each (var type:String in LobbyEvent.Events)
			{
				eventMap.mapListener(view, type, lobbyHandler);
			}
			eventMap.mapListener(view, LobbyEvent.EnterTable, socketHandler);
		}

		private function lobbyHandler(event:LobbyEvent):void
		{
			var nEvent:LobbyEvent = new LobbyEvent(event.type);
			nEvent.page = event.page;
			eventDispatcher.dispatchEvent(nEvent);
			view.lobbyHandler(event);
		}

		private function socketHandler(event:LobbyEvent):void
		{
			log('C2S_TableInto' + '\t' + event.index + '-' + event.pos);
			main.tableType = event.tableType;
			main.socket.C2S_TableInto(event.index, event.pos);
		}

		public function get main():BlackJackMain
		{
			return contextView as BlackJackMain;
		}

		private function log(value:String):void
		{
			main.debug.LOG(value);
		}
	}
}
